/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import StandardModule from '@/components/hyperspace/modules/StandardModule';
import OrderEssentialInfo from './components/OrderEssentialInfo';

let orderEssentialInfo: any = {};

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ logisticsOrder, dispatch }) => (
  <div>
    <StandardModule
      data={logisticsOrder.data}
      dictionary={[
        {
          name: 'type',
          desc: '服务类型',
          dataType: 'string',
        },
        {
          name: 'workNo',
          desc: ' 物流工作单号',
          dataType: 'string',
        },
      ]}
      config={{
        common: {
          formItemOptions: {
            username: {
              rules: [{ required: true, message: '该字段不能为空！' }],
            },
          },
        },
        search: {
          fields: ['type', 'serviceNo', 'workNo', 'customerName', 'loadingPort', 'destinationPort'], // 查询条件
          tabs: {
            field: 'status',
            tabItems: [
              {
                title: '全部',
                value: '',
                active: true,
              },
              {
                title: '补料',
                value: '1',
              },
              {
                title: '放单',
                value: '2',
              },
              {
                title: '上船',
                value: '3',
              },
            ],
          }, // 状态栏
        },
        list: {
          url: '/api/logistics/query',
          fields: [
            'id',
            'serviceNo',
            'workNo',
            'type',
            'goodsName',
            'customerName',
            'loadingPort',
            'destinationPort',
            'so',
            'cntrNo',
            'status',
            'total',
          ], // 列表字段
          format: {
            username: {
              render: (value: any) => `格式化 - ${value}`,
            },
          },
          extensions: {
            operations: [
              (record: any) => (
                <span>
                  <a
                    onClick={() => {
                      if (orderEssentialInfo) orderEssentialInfo.handleOpen();
                    }}
                  >
                    跟单
                  </a>
                </span>
              ),
            ],
          },
        },
        delete: {
          url: '/api/logistics/remove',
          batchDelete: false, // 是否开启批量删除
          fields: ['id'], // 删除依据字段
        },
      }}
      namespace="logisticsOrder"
      dispatch={dispatch}
    />
    {/* eslint-disable-next-line no-return-assign */}
    <OrderEssentialInfo wrappedComponentRef={(inst: any) => (orderEssentialInfo = inst)}
      {...orderEssentialInfo}
      visible
    />
  </div>
);

// @ts-ignore
export default connect(({ logisticsOrder }) => ({
  logisticsOrder,
}))(LocalModule);
